package imse.team0.inventoryws.parameters;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Eugen, 4/28/12 2:36 PM
 */
/*Use XmlAccessorType to avoid binding by default to get/set methods and therefore having 2 definitions
* of same property !*/

@XmlAccessorType(XmlAccessType.FIELD)
public class OrderBookStatus {
    public STATUS getStatus() {
        return status;
    }

    public void setStatus(STATUS status) {
        this.status = status;
    }

    public List<AvailableUnit> getOrderItems() {
        return orderItems;
    }

    public void setOrderItems(List<AvailableUnit> orderItems) {
        this.orderItems = orderItems;
    }

    public void addUnit (AvailableUnit unit){
        orderItems.add(new AvailableUnit(unit.getId(), unit.getRequested(), unit.getAvailable()));
    }

    public enum STATUS {
        FULFILLED,
        PARTIAL,
        TEMPORARILY_UNAVAILABLE,
        EMPTY
    }

    @XmlAttribute(name="state", required = true)
    private STATUS status;
    private List<AvailableUnit> orderItems = new ArrayList<AvailableUnit>();


    @XmlAccessorType(XmlAccessType.FIELD)
    public static class AvailableUnit {
        @XmlAttribute(name="id", required = true)
        private String id;
        @XmlAttribute(name="requested", required = true)
        private int requested;
        @XmlAttribute(name="available", required = true)
        private int available;

        public AvailableUnit() {

        }

        public AvailableUnit(String id, int requested, int available){
            this.id = id;
            this.requested = requested;
            this.available = available;
        }


        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public int getRequested() {
            return requested;
        }

        public void setRequested(int requested) {
            this.requested = requested;
        }

        public int getAvailable() {
            return available;
        }

        public void setAvailable(int available) {
            this.available = available;
        }
    }
}
